//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "server\fn_serverSetupDestroy.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_object","_actions","_action","_event","_action_id","_x","_instance_id","_event_handler"];
DEFAULT_PARAM(_object,TMF_REGISTER_OBJECT,objNull);
DEFAULT_PARAM(_action,TMF_REGISTER_ACTION,[]);
DEFAULT_PARAM(_instance_id,TMF_REGISTER_INSTANCE,TMF_SERVER_INSTANCE_ID);

if (!isnull _object) then {
	_event = [_action] call FFUNC(actionGetEvent);
	if (_event < 0) then {
		_action_id = [_action] call FFUNC(actionGetID);
		_event_handler = Format["[_this, %1] call %2;",_action_id,QUOTE(FFUNC(eventObjectiveDestroy))];
		_event = _object addEventHandler ["HandleDamage",_event_handler];
		TRACE_1("Event Added",ARR_3(typeof(_object),_event,_event_handler));
		_action = [_action, _event] call FFUNC(actionSetEvent);
		[_object, _action] call FFUNC(actionSet);
	};
} else {
	ERROR("Object not set");
};
TRACE("End");
TMFPROFILERSTOP;